package com.jack.leetcode.eachproblem_2020;

public class 完全平方数 {

    public int numSquares(int n) {
        int[] dp = new int[n + 1];
        for(int i = 0;i <= n;i++){
            dp[i] = i;
            for(int j = 1;i - j * j >= 0;j++){
                dp[i] = Math.min(dp[i], dp[i - j * j] + 1);
            }
        }
        return dp[n];
    }
}
